import { getDesktopCapturerSource, getSize, getScreenLevel, openFolder, openFile, copyFileToClipboard } from '../../utils/index'
import EventRoute from '../EventRoute'
const routers: EventRoute[] = []
import store from '../../store/index'
import { is } from '@electron-toolkit/utils'

// 获取屏幕截图源
routers.push(
  new EventRoute('screen-sources', async(_api, { data }) => {
    const type = data || 'window'
    return await getDesktopCapturerSource(type)
  })
)

// 获取屏幕截图源大小
routers.push(
  new EventRoute('screen-sources-size', async () => {
    return await getSize()
  })
)

// 获取屏幕
routers.push(
  new EventRoute('screen-sources-level', async () => {
    return await getScreenLevel()
  })
)

// 打开文件夹
routers.push(
  new EventRoute('open-folder', async (_api, { data }) => {
    return await openFolder(data)
  })
)

// 打开文件
routers.push(
  new EventRoute('open-file', async (_api, { data }) => {
    return await openFile(data)
  })
)

// 复制文件到剪切板
routers.push(
  new EventRoute('copy-file-clipboard', async (_api, { data }) => {
    return await copyFileToClipboard(data)
  })
)

// 获取快捷键
routers.push(
  new EventRoute('get-shortcuts', async (_api) => {
    const settings = store.get('applicationSettings')
    return settings
  })
)

// 设置语言
routers.push(
  new EventRoute('on-set-language', async (_api, { data }) => {
    store.set('language', data);
    return true
  })
)

// 获取语言
routers.push(
  new EventRoute('on-get-language', async (_api) => {
    return store.get('language');
  })
)

// 获取是否在局域网内
routers.push(
  new EventRoute('get-is-intranet', async (_api) => {
    if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
      return true
    } else {
      return store.get('isIntranet');
    }
  })
)

// 获取用户信息
routers.push(
  new EventRoute('get-user-info', async (_api) => {
    return store.get('userInfo')
  })
)

export default routers
